package com.contextor.magiccards.transactions.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * User: Sergey
 * Date: 20.03.2011 22:57:26
 */

//@Component
//@Aspect
public class TransactionAdvice {
    Logger logger = LoggerFactory.getLogger(getClass());

    @Pointcut("execution(public * com.contextor.magiccards.services..*.*(..)) ")
    public void processServices() {
    }

    @Pointcut("@target(org.springframework.transaction.annotation.Transactional)")
    public void processTransactionalOnly() {
    }

    @Around("processTransactionalOnly() && processServices()")
    public Object processTransaction(ProceedingJoinPoint joinPoint) {
        logger.info(joinPoint.toString());
        Object result = null;
        try {
            result = joinPoint.proceed();
        } catch (Throwable throwable) {
            logger.error("", throwable);
        }
        return result;
    }
}
